#!/usr/bin/python
import urllib
import urllib2
import json

class SimpleRequest:
    
    _data = ''
    _defaultServer = 'http://a.wykop.pl/'
    _server = ''
    _post = {}
    def _addElement(self,Element,Value = None):
        
        if Value != None:
            self._server +="/"+Element+','+Value
        else:
            self._server +="/"+Element
            
    def _addPostElement(self,Element,Value):   
        
        self._post[Element] = Value
    
    def _addAPIElement(self, appkey, userkey = None):
        self._server +='/appkey,'+appkey
        if userkey!=None:
            self._server +=',userkey,'+userkey
            
    def _send(self):
        try:
            if self._post !=None:
                self._data = urllib2.urlopen(self._defaultServer+self._server,urllib.urlencode(self._post)).read()
            else:
                self._data = urllib2.urlopen(self._defaultServer+self._server).read()
        except (urllib2.URLError, urllib2.HTTPError):
            print('error')
    
    def _getData(self):
        
        dt = self._data
        self._clear()
        return json.loads(dt)
    
    def _getRawData(self):
        dt = self._data
        self._clear()
        return dt
    def _clear(self):
        
        self._data = ''
        self._server = ''
        self._post = {}
        
        
        
    